﻿using UnityEngine;
using System.Collections;
using Dict.Blo;
using Dict.DataModel;

namespace UI
{
    public class TalentItem : MonoBehaviour
    {
        public UITexture icon;
        public UILabel labName;
        public GameObject chosedBg;
        public GameObject brightPath;
        public GameObject grayPath;
        public GameObject brighBranchtPath;
        public GameObject grayBranchPath;
        public GameObject activedAni;

        public TalentPage talentPage;

        public bool canClick;

        public bool haveChildren = false;   //是否有主干的下一节点
        public bool haveBrunchChildren = false;   //是否有分支的下一节点

        UITalent talentInfo;
        
        public void SetTalent(UITalent talent)
        {
            talentInfo = talent;

            int colorm = 150;
            if (talent.isActived || talent.isUnlocked)
                icon.color = new Color(1, 1, 1);
            else
                icon.color = new Color((float)colorm/255, (float)colorm / 255, (float)colorm / 255);

            if (activedAni != null)
                activedAni.SetActive(talent.isActived);

            if (brightPath)
                brightPath.SetActive(talent.isActived && haveChildren);
            if (grayPath)
                grayPath.SetActive(!talent.isActived && haveChildren);

            if (brighBranchtPath)
                brighBranchtPath.SetActive(haveBrunchChildren);
            if (grayBranchPath)
                grayBranchPath.SetActive(haveBrunchChildren);

            TableTalent talentData = DictTalentBlo.GetTableTalent(talent.data.talentId);
            if (talentData == null || talentData.Name == "")
                labName.text = talent.data.talentLevel;
            else
                labName.text = TableTextBlo.GetText(talentData.Name);

            //图标
            icon.GetComponent<AloneTextureKit>().SetPath("talentIcons/" + talent.data.icon);
        }

        public void SetBranchPath(bool active)
        {
            if (brighBranchtPath)
                brighBranchtPath.SetActive(active && haveBrunchChildren);
            if (grayBranchPath)
                grayBranchPath.SetActive(!active && haveBrunchChildren);
        }

        public void SetChosed(bool chose)
        {
            chosedBg.SetActive(chose);
        }

        void OnClick()
        {
            if(canClick)
                talentPage.OnTalentClick(talentInfo);
        }
    }
}
